#pragma once
#include <vector>

template<class T>
class TSimpleSymmetricMatrix
{
public:
	TSimpleSymmetricMatrix(int vElementNum) : m_ElementNum(vElementNum)
	{
		m_Elements.resize(m_ElementNum*(m_ElementNum + 1) / 2);
	}
	TSimpleSymmetricMatrix() = default;
	virtual ~TSimpleSymmetricMatrix() = default;

	T& access(int vRow, int vCol)
	{
		int Index = __calculateIndex(vRow, vCol);
		return m_Elements[Index];
	}

	int getElementNum() const
	{
		return m_ElementNum;
	}

private:
	int __calculateIndex(int vRow, int vCol) const
	{
		if (vRow < vCol)
		{
			vRow ^= vCol;
			vCol ^= vRow;
			vRow ^= vCol;
		}

		return vRow * (vRow + 1) / 2 + vCol;
	}

	int m_ElementNum = 0;
	std::vector<T> m_Elements;
};